package com.njwb.service.impl;

import com.njwb.constant.Code;
import com.njwb.json.Result;
import com.njwb.pojo.User;
import com.njwb.service.UserService;
import com.njwb.util.JWTUtil;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Override
    public Result login(User user) {
        Result result = new Result();
         //模拟用户登录
        if("sa".equals(user.getAccount()) && "ok".equals(user.getPwd())){
            //登录成功
            //生成token信息
            Map payload = new HashMap();
            payload.put("id","1");
            payload.put("account",user.getAccount());
            String token = JWTUtil.generateJWT(payload);
            result.setCode(Code.SUCCESS);
            result.setCodeMsg(Code.SUCCESS_MSG);
            result.setData(payload);
            result.setToken(token);
        }else{
            //登录不成功，省略
        }
        return result;
    }
}
